<%@page pageEncoding="UTF-8" language="java" contentType="text/html; UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">

	<link href="../../jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
	<script type="text/javascript" src="../../jquery/jquery-1.11.1-min.js"></script>
	<script type="text/javascript" src="../../jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>

	<script type="text/javascript">

		//默认情况下取消和保存按钮是隐藏的
		var cancelAndSaveBtnDefault = true;
		/*转发传递 parameter -->传递的参数 */
		var activityId = '${param.id}';
		/*加载备注*/
		function loadRemark() {
			$.ajax({
				url: "api/remarkList",
				data: {
					activityId: activityId
				},
				success: function (result) {
					var html = "";
					$.each(result.data, function (i, item) {
						html += `<div class="remarkDiv" style="height: 60px;">
                                            <img title="zhangsan" src="../../image/user-thumbnail.png" style="width: 30px; height:30px;">
                                            <div style="position: relative; top: -40px; left: 40px;">
                                                <h5>${'${item.noteContent}'}</h5>
                                                <font color="gray">市场活动</font> <font color="gray">-</font> <b>${'${item.activityId}'}</b> <small style="color: gray;">
                                                ${'${item.createTime}'} 由${'${item.createBy}'}</small>
                                                <div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">
                                                    <a class="myHref" onclick=updateRemark("${'${item.id}'}") href="javascript:void(0);"><span class="glyphicon glyphicon-edit"
                                                                                                       style="font-size: 20px; color: #E6E6E6;"></span></a>
                                                    &nbsp;&nbsp;&nbsp;&nbsp;
                                                    <a class="myHref" href="javascript:void(0);" onclick=deleteRemark("${'${item.id}'}")><span class="glyphicon glyphicon-remove"
                                                                                                       style="font-size: 20px; color: #E6E6E6;"></span></a>
                                                </div>
                                            </div>
                                        </div>`
					})
					$("#remarkList").html(html);
				}
			})
		}
		/*起步加载*/
		loadRemark()
		$(function () {
			$("#remark").focus(function () {
				if (cancelAndSaveBtnDefault) {
					//设置remarkDiv的高度为130px
					$("#remarkDiv").css("height", "130px");
					//显示
					$("#cancelAndSaveBtn").show("2000");
					cancelAndSaveBtnDefault = false;
				}
			});

			$("#cancelBtn").click(function () {
				//显示
				$("#cancelAndSaveBtn").hide();
				//设置remarkDiv的高度为130px
				$("#remarkDiv").css("height", "90px");
				cancelAndSaveBtnDefault = true;
			});

			/*未来元素 绑定事件*/
			$("#remarkList").delegate(".remarkDiv","mouseover",function () {
				$(this).children("div").children("div").show();
			})
			$("#remarkList").delegate(".remarkDiv","mouseout",function () {
				$(this).children("div").children("div").hide();
			})
			$("#remarkList").delegate(".myHref","mouseover",function () {
				$(this).children("span").css("color", "red");
			})
			$("#remarkList").delegate(".myHref","mouseout",function () {
				$(this).children("span").css("color", "#E6E6E6");
			})


			//添加保存
			$("#saveBtn").click(function () {
				if ($("#remark").val().length<1){
					alert("备注内容不能为空")
					return
				}
				let activityRemark = {
					noteContent:$("#remark").val(),
					activityId:'${param.id}'
				}

				/*发送请求*/
				$.ajax({
					url:"api/addActivityRemarks",
					data:activityRemark,
					success:function (result) {
						if (result.code==2000){
							loadRemark()
							$("#remark").val("")
						}else {
							alert(result.msg);
						}
					}
				})
			})

		});

		//删除备注
		function deleteRemark(id) {

			if (!confirm("确定删除吗")){
				return
			}
			$.ajax({
				url:"api/deleteActivityRemark",
				data:{
					//removeId 必须要和Controller中的参数一致
					removeId:id
				},
				success:function (result) {
					if (result.code==2000){
						loadRemark()
						alert("删除成功")
					}else {
						alert(result.msg)
					}
				}
			})
		}
		//修改
		$("#updateRemark").click(function () {
			if ($("#remark").val().length<1){
				alert("备注内容不能为空")
				return
			}
			let activityRemark = {
				noteContent:$("#remark").val(),

			}

			/*发送请求*/
			$.ajax({
				url:"api/updateActivityRemark",
				data:activityRemark,
				success:function (result) {
					if (result.code==2000){
						loadRemark()
						alert("修改成功")
						$("#remark").val("")
					}else {
						alert(result.msg);
					}
				}
			})

		});

	</script>

</head>
<body>

<!-- 修改市场活动备注的模态窗口 -->
<div class="modal fade" id="editRemarkModal" role="dialog">
	<%-- 备注的id --%>
	<input type="hidden" id="remarkId">
	<div class="modal-dialog" role="document" style="width: 40%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改备注</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" role="form">
					<input type="hidden" id="edit-id">
					<div class="form-group">
						<label for="edit-noteContent" class="col-sm-2 control-label">内容</label>
						<div class="col-sm-10" style="width: 81%;">
							<textarea class="form-control" rows="3" id="edit-noteContent"></textarea>
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" id="updateRemarkBtn">更新</button>
			</div>
		</div>
	</div>
</div>


<!-- 返回按钮 -->
<div style="position: relative; top: 35px; left: 10px;">
	<a href="javascript:void(0);" onclick="window.history.back();"><span class="glyphicon glyphicon-arrow-left"
																		 style="font-size: 20px; color: #DDDDDD"></span></a>
</div>

<!-- 大标题 -->
<div style="position: relative; left: 40px; top: -30px;">
	<div class="page-header">
		<h3>${activity.name} <small>${activity.startDate} ~ ${activity.endDate}</small></h3>
	</div>

</div>

<br/>
<br/>
<br/>

<!-- 详细信息 -->
<div style="position: relative; top: -70px;">
	<div style="position: relative; left: 40px; height: 30px;">
		<div style="width: 300px; color: gray;">所有者</div>
		<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${activity.owner}</b></div>
		<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">名称</div>
		<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${activity.name}</b></div>
		<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
		<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
	</div>

	<div style="position: relative; left: 40px; height: 30px; top: 10px;">
		<div style="width: 300px; color: gray;">开始日期</div>
		<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${activity.startDate}</b></div>
		<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">结束日期</div>
		<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b>${activity.endDate}</b></div>
		<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
		<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
	</div>
	<div style="position: relative; left: 40px; height: 30px; top: 20px;">
		<div style="width: 300px; color: gray;">成本</div>
		<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b>${activity.cost}</b></div>
		<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -20px;"></div>
	</div>
	<div style="position: relative; left: 40px; height: 30px; top: 30px;">
		<div style="width: 300px; color: gray;">创建者</div>
		<div style="width: 500px;position: relative; left: 200px; top: -20px;">
			<b>${activity.createBy}&nbsp;&nbsp;</b><small
				style="font-size: 10px; color: gray;">${activity.createTime}</small></div>
		<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
	</div>
	<div style="position: relative; left: 40px; height: 30px; top: 40px;">
		<div style="width: 300px; color: gray;">修改者</div>
		<div style="width: 500px;position: relative; left: 200px; top: -20px;">
			<b>${activity.editBy}&nbsp;&nbsp;</b><small
				style="font-size: 10px; color: gray;">${activity.editTime}</small></div>
		<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
	</div>
	<div style="position: relative; left: 40px; height: 30px; top: 50px;">
		<div style="width: 300px; color: gray;">描述</div>
		<div style="width: 630px;position: relative; left: 200px; top: -20px;">
			<b>
				${activity.description}
			</b>
		</div>
		<div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
	</div>
</div>

<!-- 备注 -->
<div style="position: relative; top: 30px; left: 40px;">
	<div class="page-header">
		<h4>备注</h4>
	</div>

	<%--提供一个div 存入 生产的 备注--%>

	<div id="remarkList">

	</div>
	<!-- 备注1 -->
	<%--<div class="remarkDiv" style="height: 60px;">
        <img title="zhangsan" src="../../image/user-thumbnail.png" style="width: 30px; height:30px;">
        <div style="position: relative; top: -40px; left: 40px;">
            <h5>哎呦！</h5>
            <font color="gray">市场活动</font> <font color="gray">-</font> <b>发传单</b> <small style="color: gray;">
            2017-01-22 10:10:10 由zhangsan</small>
            <div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">
                <a class="myHref" href="javascript:void(0);"><span class="glyphicon glyphicon-edit"
                                                                   style="font-size: 20px; color: #E6E6E6;"></span></a>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <a class="myHref" href="javascript:void(0);"><span class="glyphicon glyphicon-remove"
                                                                   style="font-size: 20px; color: #E6E6E6;"></span></a>
            </div>
        </div>
    </div>--%>


	<div id="remarkDiv" style="background-color: #E6E6E6; width: 870px; height: 90px;">
		<form role="form" style="position: relative;top: 10px; left: 10px;">
            <textarea id="remark" class="form-control" style="width: 850px; resize : none;" rows="2"
					  placeholder="添加备注..."></textarea>
			<p id="cancelAndSaveBtn" style="position: relative;left: 737px; top: 10px; display: none;">
				<button id="cancelBtn" type="button" class="btn btn-default">取消</button>
				<button type="button" id="saveBtn" class="btn btn-primary">保存</button>
			</p>
		</form>
	</div>
</div>
<div style="height: 200px;"></div>
</body>
</html>